package com.wanghlme.day25.dom4j;

import com.wanghlme.day25.dom.DomParse;
import com.wanghlme.day25.pojo.Student;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;

public class DomForParse {
    public List<Student> parseXml() {
        List<Student> list = new ArrayList<>();
        InputStream inputStream = DomParse.class.getClassLoader().getResourceAsStream("data.xml");
        SAXReader saxReader = new SAXReader();
        Document doc = null;
        try {
            doc = saxReader.read(inputStream);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        assert doc != null;
        Element ele = doc.getRootElement();
        Iterator<Element> it = ele.elementIterator();
        while (it.hasNext()) {
            Element stuEle = it.next();
            Student stu = new Student();
            list.add(stu);
        }
        return list;
    }

}
